# 6_6 屏幕使用：海龟作图
# https://learn.adafruit.com/circuitpython-display-support-using-displayio
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/ui-quickstart
# https://learn.adafruit.com/custom-fonts-for-pyportal-circuitpython-display

'''
6. 海龟作图
'''
import board
from adafruit_turtle import Color, turtle

# 1. 屏幕基础配置
display = board.DISPLAY

# 6. 海龟作图

# 初始化海龟
turtle = turtle(display)

# 计算尺寸
starsize = min(board.DISPLAY.width, board.DISPLAY.height) * 0.8  # 90% of screensize

# 设置笔的颜色
turtle.pencolor(Color.BLUE)
# 抬笔
turtle.penup()
# 移动
turtle.goto(-starsize/2, -starsize/2)
# 落笔
turtle.pendown()

# 绘图
start = turtle.pos()
while True:
    turtle.forward(starsize)
    turtle.left(170)
    if abs(turtle.pos() - start) < 1:
        break

# 计算尺寸
benzsize = min(board.DISPLAY.width, board.DISPLAY.height) * 0.5
# 设置颜色
colors = (Color.RED, Color.ORANGE, Color.YELLOW, Color.GREEN, Color.BLUE, Color.PURPLE)

# 抬笔-移动-落笔
turtle.penup()
turtle.goto(+starsize/2, 0)
turtle.pendown()

# 绘图
for x in range(benzsize):
    turtle.pencolor(colors[x%6])
    turtle.forward(x)
    turtle.left(59)
